package com.CGFrame.struts.action.categorySet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.CGFrame.struts.bean.category.CatemodeltimeBean;
import com.CGFrame.struts.bean.log.LogHistoryBean;

public class NewModelCateAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse resoponse) throws Exception {
		String categoryId=request.getParameter("categoryId");
		String hours=request.getParameter("hours");
		String modelId=request.getParameter("modelId");
		
		String result="ExpectTime can not be null!";
		if(hours!=""){
			CatemodeltimeBean ctb=new CatemodeltimeBean();
			Integer resultId =ctb.addCatemodeltime(Integer.valueOf(modelId),Integer.valueOf(categoryId),Integer.valueOf(hours));
			if (resultId ==null) result="HasExisted";
			else
			{
				result="Success";

				LogHistoryBean logBean = new LogHistoryBean();
				String regUserId = (String)request.getSession().getAttribute("RegUserID");
				logBean.saveByReguserId(regUserId, LogHistoryBean.ADD,null, "Catemodeltime", resultId );
			}
		}
		request.setAttribute("modelId", modelId);
		request.setAttribute("NewModelCateResult", result);
		
		return mapping.findForward("detail");
	}
}
